package Chouxianglei;

import javax.swing.*;

public class lianxi {
    public static void main(String[] args) {
        Income[] incomes = new Income[]{
                new salarys(3000),
                new gaofeis(12000),

        };
        System.out.println(TotalTax(incomes));
    }
    public static double TotalTax(Income... incomes) {
        double total = 0;
        for (Income income : incomes) {
            total += income.getTax();
        }
        return total;
    }
}

abstract class Income{
    protected double income;
    public Income(double income){
        this.income = income;
    }
//    public double totalTxt(Income...incomes){
//        return income*0.1;
//    }
    public abstract double getTax();

}
class salarys extends Income{
    public salarys(double income){
        super(income);
    }

    @Override
    public double getTax(){
        if (income<5000){
            return 0;
        }
        else {
           return  (income-5000)*0.2;
        }
    }
}
class gaofeis extends Income{
    public gaofeis(double income){
        super(income);
    }

    @Override
    public double getTax() {
        return income*0.3;
    }

}
